package cn.springboot.erp.service.impl;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.exception.excel.ExcelImportException;
import cn.hutool.core.util.ObjectUtil;
import cn.springboot.erp.commons.QueryParams;
import cn.springboot.erp.commons.ResponseResult;
import cn.springboot.erp.exception.CustomerNameException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.springboot.erp.entity.Categories;
import cn.springboot.erp.service.CategoriesService;
import cn.springboot.erp.mapper.CategoriesMapper;
import org.springframework.stereotype.Service;

/**
* @author asus
* @description 针对表【categories】的数据库操作Service实现
* @createDate 2024-05-07 16:01:07
*/
@Service
public class CategoriesServiceImpl extends ServiceImpl<CategoriesMapper, Categories>
    implements CategoriesService{

    @Override
    public ResponseResult listPage(QueryParams<Categories> queryParams) {
        // 获取分页数据
        Categories searchParams = queryParams.getSearchParams();
        Integer page = queryParams.getPage();
        Integer limit = queryParams.getLimit();
        // 数据分页
        Page<Categories> categoriesPage = new Page<>(page, limit);
        // 查询数据
        LambdaQueryWrapper<Categories> lambda = new QueryWrapper<Categories>().lambda();
        lambda.eq(StringUtils.isNotBlank(searchParams.getName()),Categories::getName,searchParams.getName())
                .orderByDesc(Categories::getCreateTime);
        baseMapper.selectPage(categoriesPage,lambda);
        return ResponseResult.Success()
                .data("total",categoriesPage.getTotal())
                .data("categoriesList",categoriesPage.getRecords());
    }

}




